<?php
ini_set("error_reporting",E_ALL);
use Kanin\Games\lib\Config;
use Kanin\Games\lib\Tool;
use Kanin\Games\model\TableIds;
use Kanin\Games\model\User;

require_once __DIR__."/../../../vendor/autoload.php";
require_once __DIR__."/../../init.php";
$type = $argv[1];

$upData = [
	'level'=> 1
];
$status = User::update($upData, 1);
$status->getMatchedCount();
if ($type == '-c') {
	list($username, $password) = explode(':', $argv[2]);

    /**
     * @var \Kanin\Games\model\User $model
     */
    $model = Tool::model('user');

    try {
        $user = $model->getOne(['username' => $username]);
    } catch (\Kanin\MyTools\Exception\KMongoException|\MongoDB\Driver\Exception\Exception $e) {
        var_dump($e->getMessage());
    }
    if ($user) {
		echo "用户 \"{$username}\" 已存在" . PHP_EOL;
		exit;
	}
    try {
        $res = $model->create($username, $password);
    } catch (\Kanin\MyTools\Exception\KMongoException $e) {
        var_dump($e->getMessage());
    }
    if ($res) {
		echo '成功' . PHP_EOL;
	} else {
		echo '失败' . PHP_EOL;
	}
	exit;
}